﻿namespace NJQuery {
	using System;
	using System.Web.UI;
	using System.Web.UI.WebControls;
	using System.ComponentModel;
	using System.Diagnostics.CodeAnalysis;

	/// <summary>
	/// Server control used to generate inner markup needed for each panel of a <see href="http://jqueryui.com/demos/tabs/">jQuery UI Tabs widget</see>.
	/// </summary>
	public class TabPanel : ChildPanel {


		#region Constants: Property defaults

		private const string defaultAjaxContentUrl = "";
		private const string defaultTab = "";

		#endregion


		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="TabPanel"/> class.
		/// </summary>
		public TabPanel() : base(HtmlTextWriterTag.Div) { }

		#endregion


		#region Properties

		/// <summary>
		/// Gets or sets a url that, when provided, will cause the panel not to render its contents, but rather load its contents from an HTML snippet located at the destination URL when the user clicks on the tab.
		/// </summary>
		[DefaultValue(defaultAjaxContentUrl), Category("Behavior"), UrlProperty]
		[SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "Does not appear to be common in the control world, particularly with the ~/ ResolveUrl logic.")]
		public virtual string AjaxContentUrl {
			get { return ViewState["AjaxContentUrl"] as string ?? defaultAjaxContentUrl; }
			set { ViewState["AjaxContentUrl"] = value; }
		}

		/// <summary>
		/// Gets or sets the text to display on the tab selector in the <see cref="Tabs"/> widget.
		/// HTML is allowed, so any text must HTML encoded.
		/// </summary>
		[DefaultValue(defaultTab), PersistenceMode(PersistenceMode.InnerProperty)]
		public virtual string Tab {
			get { return ViewState["Tab"] as string ?? defaultTab; }
			set { ViewState["Tab"] = value; }
		}

		#endregion


		#region Rendering hooks

		/// <summary>
		/// Sends server control content to a provided <see cref="HtmlTextWriter"/> object, which writes the content to be rendered to the client.
		/// This method is used primarily by control developers.
		/// </summary>
		/// <param name="writer">A <see cref="HtmlTextWriter"/> that represents the output stream to render HTML content on the client.</param>
		public override void RenderControl(HtmlTextWriter writer) {

			if(!string.IsNullOrEmpty(AjaxContentUrl)) return;

			base.RenderControl(writer);
		}

		#endregion


	}

}